public class problem34 {
    public static void main(String[] args) {
        Long sum = 0L;
        Long number = 3L;
        Long numberSum = 0L;
        while (true) {
            String numberString = number.toString();
            for (int counter = 0; counter < numberString.length(); counter++) {
                Long digit = Long.valueOf(numberString.substring(counter, counter + 1));
                numberSum += ProjectEuler.getFactorial(digit);
            }

            if (numberSum.equals(number)) {
                sum += number;
                System.out.println(sum);
            }

            number++;
            numberSum = 0L;
        }
    }

}
